package com.example.springbootServiceNetwork.demos.web.Controller;


import com.example.springbootServiceNetwork.demos.web.Config.JwtInfo;
import com.example.springbootServiceNetwork.demos.web.Config.Result;
import com.example.springbootServiceNetwork.demos.web.Dto.SparkParamDto;
import com.example.springbootServiceNetwork.demos.web.Entity.LargeModel;
import com.example.springbootServiceNetwork.demos.web.Entity.SparkChat;
import com.example.springbootServiceNetwork.demos.web.Service.JwtRedistService;
import com.example.springbootServiceNetwork.demos.web.Service.SparkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;


@RestController
@RequestMapping("/Spark")
public class SparkController {
    @Resource
    private SparkService sparkService;
    @Resource
    private JwtRedistService jwtRedistService;


    /**
     * 与模型发起会话聊天
     * @param sparkParam
     * @param token
     */
    @PostMapping("/chat")
    public Result SparkChatApi(@RequestBody SparkParamDto sparkParam, @RequestHeader("token") String token){
        JwtInfo jwtInfo = jwtRedistService.getUserInfo(token);
        if(jwtInfo.getPass()){
            return sparkService.SparkChat(sparkParam,jwtInfo);
        }else {
            return jwtInfo.getResult();
        }
    }

    /**
     * 添加历史会话记录
     * @param sparkChat
     */
    @PostMapping("/addSparkChat")
    public Result addSparkChat(@RequestBody SparkChat sparkChat,@RequestHeader("token") String token){
        JwtInfo jwtInfo = jwtRedistService.getUserInfo(token);
        System.out.println(sparkChat);
        if(jwtInfo.getPass()){
            sparkChat.setUserId(jwtInfo.getUserId());
            return  sparkService.addSparkChat(sparkChat);
        }else {
            return jwtInfo.getResult();
        }
    }

    /**
     * 删除历史会话记录
     * @param sparkChatList
     */
    @PostMapping("/deleteSparkChat")
    public Result deleteSparkChat(@RequestBody List<SparkChat> sparkChatList){
        return  sparkService.deleteSparkChat(sparkChatList);
    }

    /**
     * 更新历史会话记录
     * @param sparkChat
     */
    @PostMapping("/updateSparkChat")
    public Result updateSparkChat(@RequestBody SparkChat sparkChat){
        return  sparkService.updateSparkChat(sparkChat);
    }

    /**
     * 查询历史会话记录
     */
    @GetMapping("/querySparkChat")
    public Result querySparkChat(@RequestHeader("token") String token){
        JwtInfo jwtInfo = jwtRedistService.getUserInfo(token);
        if(jwtInfo.getPass()){
            return sparkService.querySparkChat(jwtInfo);
        }else {
            return jwtInfo.getResult();
        }
    }

    /**
     * 查询模型分类
     */
    @GetMapping("/queryAllLargeMode")
    public Result queryAllLargeMode(@RequestHeader("token") String token){
        JwtInfo jwtInfo = jwtRedistService.getUserInfo(token);
        if(jwtInfo.getPass()){
            return sparkService.queryAllLargeMode(jwtInfo);
        }else {
            return jwtInfo.getResult();
        }
    }

    /**
     * 新增模型分类
     */
    @PostMapping("/addLargeMode")
    public Result queryAllLargeMode(@RequestBody LargeModel largeModel){
        return sparkService.addLargeMode(largeModel);
    }
    /**
     * 更新模型分类
     */
    @PostMapping("/updateLargeMode")
    public Result updateLargeMode(@RequestBody LargeModel largeModel){
        return sparkService.updateLargeMode(largeModel);
    }

    /**
     * 删除模型分类
     */
    @PostMapping("/deleteLargeMode")
    public Result deleteLargeMode(@RequestBody List<LargeModel> largeModelList){
        System.out.println(largeModelList);
        return sparkService.deleteLargeMode(largeModelList);
    }


}
